import api from "../../../utils/util.js"
const app = getApp()
Page({
  data: {
    showpicker: false,
    modalName: '',
    Today: {
      week: 2,
      theDay: ''
    },
    // 课表颜色
    colorArrays: ["#9b5de5", "#f15bb5", "#00bbf9", "#ffbe0b", "#fb5607", "#ff006e", "#8338ec", "#3a86ff"],
    // 课表数据
    DataList: [],
    SystemInfo: {
      Height: 660,
    },
  },
  onChange(event) {
    const { picker, value, index } = event.detail;
  },
  //下一周课表
  Nextweek(event) {

    const curr = this.data.Today.week.week
    if (curr < 22) {
      this.setData({
        Today: {
          week: {
            week: curr + 1
          }
        }
      })
      this.GetList();
    } else {
      return false
    }

  },
  //上一周课表
  Lastweek(event) {
    console.log(this.data.Today.week.week)
    const curr = this.data.Today.week.week
    if (curr > 1) {
      this.setData({
        Today: {
          week: {
            week: curr - 1
          }
        }
      })
      this.GetList();
    } else {
      return false
    }

  },
  //获取课表
  GetList(update = false) {
    this.setData({
      DataList: '',
    })

    qq.showLoading({
      title: '加载中',
    })
    const that = this;
    api.getC({
      success(res) {
        console.log('html' + res)
        that.setData({
          DataList: res,
        })
        qq.hideLoading()
      }
    }, that.data.Today.week.week, update);
  },
  onLoad: function () {
    const theDay = api.getTheday()
    const week = api.getWeek()


    this.setData({
      Today: {
        week: week,
        theDay: theDay
      }
    })

    this.GetList();
    const that = this;
    qq.getSystemInfo({
      success(res) {
        const statusBarHeight = (750 / res.windowWidth) * res.statusBarHeight
        const Height = (750 / res.windowWidth) * res.windowHeight - statusBarHeight - 200;

        that.setData({
          SystemInfo: {
            Height,
            statusBarHeight
          }
        })
      }
    })

  },
  showModal(e) {
    this.setData({
      modalName: 'bottomModal'
    })
  },
  onPullDownRefresh: function () {
    this.GetList(true);
    qq.stopPullDownRefresh()
  },
  onShareAppMessage: function () {
    return {
      title: "邀您使用",
      desc: "「工程课表」提供工程职院在校生师生课表等查询服务。",
      path: "/pages/index/index"
    }
  },
  showpickerl: function (res) {
    console.log('xxxx')
    this.setData({ showpicker: true });

  },
  onClose() {
    console.log('onClose')
    this.setData({ showpicker: false });
  },
  onConfirm(event) {
    console.log('onConfirm')
    this.setData({ showpicker: false });
    const { picker, value, index } = event.detail;
    // Toast(`当前值：${value}, 当前索引：${index}`);
  },
  showCardView: function (res) {
    // this.setData({
    //   modalName: 'bottomModal'
    // })
    var a = this.data.DataList.filter((function (t) {
      return t.id === res.currentTarget.dataset.id
    }))
    var n = a[0];
    qq.showModal({
      title: n.courseName,
      showCancel: !1,
      content: JSON.stringify(n)
    })
  }
})